goog.provide('BombBall');

goog.require('Stefan.Timer');
goog.require('BombBall.Map');


var BombBall = {
	STAGE_WIDTH: 800,
	STAGE_HEIGHT: 600,
	GRIDSIZE: 50
};
BombBall.GAME = (function() {
	return {
		start: function() {
			this.map = new BombBall.Map({
			});
			
			this.schedule();
			
			var __this = this;
			T.on('addBall', 'click', function(event){
				var b = new BombBall.Ball({
					x: 200
					,y: 200
					,map: __this.map
					,color: 'rgba(123,200,123,.8)'
					,draggable: false
				});
			});
		},
		schedule: function() {
		    Stefan.Timer.register(this.step);
		    Stefan.Timer.active();
		},
		step: function() {
			var balls = BombBall.GAME.map.balls;
			for(var i=0; i<balls.length-1; i++){
				for(var j=i+1; j<balls.length; j++){
					BombBall.Ball.judgeCrash(balls[i],balls[j]);
				}
			}
			if(BombBall.GAME.map.time > 0){
				BombBall.GAME.map.time --;
			}
			T.g("time").innerHTML = BombBall.GAME.map.time;
			for(var i=0; i<balls.length; i++){
	    		balls[i].step();
	    	}
		}
	}
})();


